package com.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.listener.HibernateListener;
import com.pojo.County;

public class CountyDAO {

	@SuppressWarnings("unchecked")
	public County getCountyByCountyName(String countyName) {
		String sql = "select new com.pojo.County(a.countyId, a.countyName) "
				+ " from County as a where countyName like '" + countyName + "'";
		Session session = HibernateListener.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		Query query = session.createQuery(sql);
		List<County> list = query.list();
		transaction.commit();
		return list.get(0);
	}
	
	@SuppressWarnings("unchecked")
	public County listCounty(){
		String sql = "from County";
		Session session = HibernateListener.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		Query query = session.createQuery(sql);
		List<County> listc = query.list();
		transaction.commit();
		return listc.get(0);
	}
}
